﻿using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using Newtonsoft.Json;
using SqlSugar;
using ztDataNet.db;
using static Google.Protobuf.Reflection.SourceCodeInfo.Types;

namespace ztDataNet.Controllers
{
    public class CalendarListController : BaseController<CalendarList>
    {
        private readonly ISqlSugarClient db;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="db"></param>
        /// <param name="cc"></param>
        public CalendarListController(ISqlSugarClient db, IDistributedCache cc) : base(db, cc)
        {
            this.db = db;
        }
        /// <summary>
        /// 根据id查询单条
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        // GET: api/Entity/Get/{id}
        [HttpGet("GetOpenid/{id}/{date}")]
        public async Task<IActionResult> GetEntityByopenid(string id,string date)
        {

            // 如果缓存中没有数据，从数据库中获取数据
            var result = await db.Queryable<CalendarList>().Where(x => x.openid == id).Where(x=>x.date == date).ToListAsync();

            // 将数据序列化为JSON
            var serializedResult = JsonConvert.SerializeObject(result);

            // 将数据存储到缓存中，设置滑动过期时间为5分钟

            if (result == null)
            {
                return Ok("no");
            }
            else
            {
                return Ok(result);
            }

        }
        [HttpGet("pushWXmessage")]
        public async Task<IActionResult> pushWXmessage(string touser, string thing3, string thing10, string phrase5)
        {


            var openId = utils.Send_Subscribe(touser, thing3, thing10, phrase5);
                //业务处理
                return Ok(openId);
           

        }
    }
}

